Scheduler
The scheduler class — available via require — can be used to easily set up coroutine-based cooperative multitasking.
__construct
The constructor takes no arguments.
add
The add method can be used to turn a function into a coroutine. The coroutine is resumed once, added to the scheduler, and returned.
addloop
The addloop method is a wrapper for the add method that keeps invoking the given function until it returns false.
run
The run method activates the scheduler. The scheduler resumes all coroutines and then calls its yieldfunc until either all coroutines are finished, or a coroutine throws an error — in which case it is rethrown.
pluto
yieldfunc
yieldfunc is a property on the scheduler that can be used to customize how the scheduler itself yields. By default, this is a function calling os.sleep(1).
pluto
errorfunc
errorfunc is a property on the scheduler that can optionally be set to customize how the scheduler reports errors in its coroutines. By default, this is nil, in which case any coroutine errors are rethrown (via coroutine.xresume).
pluto